package com.example.demo4;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

import androidx.annotation.Nullable;

public class TitleLayout extends LinearLayout {
    public TitleLayout(final Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        //加载动态布局
        LayoutInflater.from(context).inflate(R.layout.title,this);
        //注册点击事件
        Button button_black=findViewById(R.id.button_black);
        Button button_menu=findViewById(R.id.button_menu);
        button_black.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                ((Activity)getContext()).finish();
            }
        });
        button_menu.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context,"菜单还在开发中",Toast.LENGTH_SHORT).show();
            }
        });

    }
}
